import * as Cesium from 'cesium/Cesium'

var ArcType = {
    NONE: 0,
    GEODESIC: 1,
    RHUMB: 2
}

function PolylinePrimitive(e) {
    e = Cesium.defaultValue(e, Cesium.defaultValue.EMPTY_OBJECT),
        this.show = Cesium.defaultValue(e.show, !0),
        this._ellipsoid = Cesium.defaultValue(e.ellipsoid, Cesium.Ellipsoid.WGS84),
        this._width = Cesium.defaultValue(e.width, 3),
        this._color = Cesium.Color.clone(Cesium.defaultValue(e.color, Cesium.Color.WHITE)),
        this._id = Cesium.createGuid(),
        this._positions = Cesium.defaultValue(e.positions, []),
        this._primitive = void 0,
        this._boundingSphere = new Cesium.BoundingSphere,
        this._dashed = Cesium.defaultValue(e.dashed, !1),
        this._loop = Cesium.defaultValue(e.loop, !1),
        this._update = !0
}

Cesium.defineProperties(PolylinePrimitive.prototype, {
    positions: {
        get: function () {
            return this._positions
        },
        set: function (e) {
            this._positions = e,
                this._update = !0
        }
    },
    color: {
        get: function () {
            return this._color
        }
    },
    boundingVolume: {
        get: function () {
            return this._boundingSphere
        }
    },
    width: {
        get: function () {
            return this._width
        }
    },
    ellipsoid: {
        get: function () {
            return this._ellipsoid
        }
    },
    dashed: {
        get: function () {
            return this._dashed
        }
    },
    loop: {
        get: function () {
            return this._loop
        }
    }
}),
    PolylinePrimitive.prototype.update = function (e) {
        if (this.show) {
            var t = this._positions;
            if (!Cesium.defined(t) || t.length < 2)
                this._primitive = this._primitive && this._primitive.destroy();
            else {
                if (this._update) {
                    this._update = !1,
                        this._id = this.id,
                        this._primitive = this._primitive && this._primitive.destroy(),
                    this._loop && (t = t.slice()).push(t[0]);
                    var i, r = new Cesium.PolylineGeometry({
                        positions: t,
                        width: this.width,
                        vertexFormat: Cesium.PolylineMaterialAppearance.VERTEX_FORMAT,
                        ellipsoid: this._ellipsoid,
                        arcType: ArcType.NONE
                    });
                    i = this._dashed ? new Cesium.PolylineMaterialAppearance({
                        material: Cesium.Material.fromType(Cesium.Material.PolylineDashType, {
                            color: this._color
                        })
                    }) : new Cesium.PolylineColorAppearance,
                        this._primitive = new Cesium.Primitive({
                            geometryInstances: new Cesium.GeometryInstance({
                                geometry: r,
                                attributes: {
                                    color: Cesium.ColorGeometryInstanceAttribute.fromColor(this._color),
                                    depthFailColor: Cesium.ColorGeometryInstanceAttribute.fromColor(this._color)
                                },
                                id: this.id
                            }),
                            appearance: i,
                            depthFailAppearance: i,
                            asynchronous: !1,
                            allowPicking: !1
                        }),
                        this._boundingSphere = Cesium.BoundingSphere.fromPoints(t, this._boundingSphere)
                }
                this._primitive.update(e)
            }
        }
    }
    ,
    PolylinePrimitive.prototype.isDestroyed = function () {
        return !1
    }
    ,
    PolylinePrimitive.prototype.destroy = function () {
        return this._primitive = this._primitive && this._primitive.destroy(),
            Cesium.destroyObject(this)
    }
export default PolylinePrimitive;